package com.rdExpenses.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.common.service.CrudService;
import com.rdExpenses.dao.ExpenseAssignItemMapper;
import com.rdExpenses.model.ExpenseAssign;
import com.rdExpenses.model.ExpenseAssignItem;
import com.rdExpenses.service.ExpenseAssignItemService;

@Service
public class ExpenseAssignItemServiceImpl extends CrudService<ExpenseAssignItemMapper, ExpenseAssignItem> implements
		ExpenseAssignItemService {
	public boolean saveExpenseAssign(ExpenseAssignItem expenseAssignItem) throws Exception {
		this.saveOrUpdate(expenseAssignItem);
		return true;
	}

	public boolean deleteExpenseAssign(String assignId) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("assignId", assignId);
		String sql = "delete FROM expense_assign_item  where expense_assign_id = '" + assignId + "'";
		this.delete(sql);
		return true;
	}

	public List<ExpenseAssignItem> findExpenseAssignItemByAssignId(String assignId) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("assignId", assignId);
		String sql = "SELECT i.id,i.expense_assign_id,i.project_id,i.rate,p.project_name "
				+ "FROM expense_assign_item  i ,company_project  p "
				+ "where i.project_id = p.id and i.expense_assign_id = #{assignId} ";

		List<ExpenseAssignItem> list = this.getList(sql, ExpenseAssignItem.class, params);
		return list;
	}
}
